<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="年月日" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dateTime">
              <a-input v-model="model.dateTime"placeholder="请输入年月日" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="日照时长" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lengthOfSunshine">
              <a-input v-model="model.lengthOfSunshine"placeholder="请输入日照时长" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最小气温" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="minTem">
              <a-input v-model="model.minTem"placeholder="请输入最小气温" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最大气温" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maxTem">
              <a-input v-model="model.maxTem"placeholder="请输入最大气温" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="湿度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hum">
              <a-input v-model="model.hum"placeholder="请输入湿度" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="风速" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wind">
              <a-input v-model="model.wind"placeholder="请输入风速" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="降雨" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rainfall">
              <a-input v-model="model.rainfall"placeholder="请输入降雨" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地下水位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="waterTable">
              <a-input v-model="model.waterTable"placeholder="请输入地下水位" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="播种日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sowingDate">
              <a-input v-model="model.sowingDate"placeholder="请输入播种日期" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="苗期末" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="miaoEnd">
              <a-input v-model="model.miaoEnd"placeholder="请输入苗期末" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="蕾期末" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leiEnd">
              <a-input v-model="model.leiEnd"placeholder="请输入蕾期末" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="花期末" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="huaEnd">
              <a-input v-model="model.huaEnd"placeholder="请输入花期末" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="龄期末" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lingEnd">
              <a-input v-model="model.lingEnd"placeholder="请输入龄期末" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="吐絮期末" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tuxuEnd">
              <a-input v-model="model.tuxuEnd"placeholder="请输入吐絮期末" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="苗期盐分阈值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="miaoSalt">
              <a-input v-model="model.miaoSalt"placeholder="请输入苗期盐分阈值" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="蕾期盐分阈值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leiSalt">
              <a-input v-model="model.leiSalt"placeholder="请输入蕾期盐分阈值" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="花期龄期盐分阈值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="huaLingSalt">
              <a-input v-model="model.huaLingSalt"placeholder="请输入花期龄期盐分阈值" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="吐絮期盐分阈值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tuxuSalt">
              <a-input v-model="model.tuxuSalt"placeholder="请输入吐絮期盐分阈值" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="苗期水分阈值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="miaoWater">
              <a-input v-model="model.miaoWater"placeholder="请输入苗期水分阈值" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="蕾期水分阈值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leiWater">
              <a-input v-model="model.leiWater"placeholder="请输入蕾期水分阈值" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="花期龄期水分阈值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="huaLingWater">
              <a-input v-model="model.huaLingWater"placeholder="请输入花期龄期水分阈值" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="吐絮期水分阈值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tuxuWater">
              <a-input v-model="model.tuxuWater"placeholder="请输入吐絮期水分阈值" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="田间持水率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fieldWaterRate">
              <a-input v-model="model.fieldWaterRate"placeholder="请输入田间持水率" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="排盐系数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="saltDischarge">
              <a-input v-model="model.saltDischarge"placeholder="请输入排盐系数" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="滴灌系数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dripDischarge">
              <a-input v-model="model.dripDischarge"placeholder="请输入滴灌系数" ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: "WfimModelDriveParamsModal",
    components: {
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        title:"操作",
        width:800,
        visible: false,
        model:{
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/wfim/wfimModelDrive/addWfimModelDriveParams",
          edit: "/wfim/wfimModelDrive/editWfimModelDriveParams",
        }

      }
    },
    created () {
    //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            this.model['mainId'] = this.mainId
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false
          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>
